package ThreadPool.lagou.concurrent.lock.demo01;

import java.util.concurrent.TimeUnit;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description:TODO
 * @date 2022/10/8 18:45
 */
public class LockDemo {




    public static void main(String[] args) {
        Phone phone = new Phone();
        new Thread(()->{
            phone.sendEmail();
        },"a").start();


        new Thread(()->{
            //phone.sendSms();
            phone.sendHello();
        },"b").start();
    }
}

class Phone{
    public synchronized void sendEmail(){
//        try {
//            TimeUnit.SECONDS.sleep(2);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
        int i = 10/0;
        System.out.println("发送邮件...");
    }

    public synchronized void sendSms(){
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("发送短信...");
    }

    public void sendHello(){
        System.out.println("Hello");
    }
}
